<#assign defaultAssets={
} />

<#if !configs?? || configs['dev.mode']=='1' || (request.queryString?? && request.queryString?length gt 0 && request.queryString?index_of('dajieuedtest=1') gte 0)>
    <#assign shouldMergeAssets=false/>
    <#else>
        <#assign shouldMergeAssets=true/>
</#if>

<#if (application.assetsMap)??>
    <#assign assetsDataMap = application.assetsMap/>
    <#elseif assetsMap??>
        <#assign assetsDataMap = assetsMap/>
    <#else>
        <#assign assetsDataMap = {}/>
</#if>
<#function WrapperAssetsWithVersion assets>
    <#if (!assets?ends_with(".css") && !assets?ends_with(".js")) || !shouldMergeAssets || !(assetsDataMap[assets])??>
        <#return assets/>
    </#if>
    <#if assets?ends_with(".css")>
        <#return assets?substring(0,assets?last_index_of(".css")) + "." + assetsDataMap[assets] + ".css"/>
        <#else>
            <#return assets?substring(0,assets?last_index_of(".js")) + "." + assetsDataMap[assets] + ".js"/>
    </#if>
</#function>
<#macro MergeAssets type assets=[] >
    <#assign isStart=true>
    <#assign concatAssets = ''>
    <#list assets as file>
        <#if file?ends_with('.${type}') && !defaultAssets[file]?? && assetsDataMap[file]??>
            <#if isStart>
                <#assign concatAssets = WrapperAssetsWithVersion(file)/>
                <#assign isStart = false/>
                <#else>
                    <#assign concatAssets = concatAssets + ',' + WrapperAssetsWithVersion(file)/>
            </#if>
        </#if>
    </#list>
    <#if concatAssets?length gt 0 && type='css'>
    <link rel="stylesheet" type="text/css" href="<@url>??${concatAssets}</@url>"/>
    <#elseif concatAssets?length gt 0 && type='js'>
    <script type="text/javascript" src="<@url>??${concatAssets}</@url>"></script>
    </#if>
</#macro>
<#macro csselement file="">
    <#if file?length gt 0>
    <link rel="stylesheet" type="text/css" href="<@url>${WrapperAssetsWithVersion(file)}</@url>"/>
    </#if>
</#macro>
<#macro jselement file="">
    <#if file?length gt 0>
    <script type="text/javascript" src="<@url>${WrapperAssetsWithVersion(file)}</@url>"></script>
    </#if>
</#macro>
<#macro AssetsImport assets=[]>
    <#assign newAssets = ["/up/dj-mobile/css/base.css","/up/dj-mobile/css/frame.css","/up/dj-mobile/js/zepto.min.js","/up/dj-mobile/js/zepto.cookie.js","/up/dj-mobile/js/zepto.publish.js","/up/dj-mobile/js/touch.js","/up/dj-mobile/js/back.js"] + assets/>
    <#if shouldMergeAssets>
        <@MergeAssets type='css' assets=newAssets/>
        <@MergeAssets type='js' assets=newAssets/>
        <#else>
            <#list defaultAssets?keys as file>
                <#if file?ends_with('.js')>
                <@jselement file='${file}' />
                    <#else>
                    <@csselement file='${file}' />
                </#if>
            </#list>
            <#list newAssets as file>
                <#if !defaultAssets[file]?? && (file?ends_with('.js') || file?ends_with('.css'))>
                    <#if file?ends_with('.js')>
                    <@jselement file='${file}' />
                        <#else>
                        <@csselement file='${file}' />
                    </#if>
                </#if>
            </#list>
    </#if>
    <#if requiredJs??>
        <#list requiredJs as file>
        <@jselement file='${file}' />
        </#list>
    </#if>
</#macro>
